package com.sai.utils;

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

public class Utilities {
    
    public Utilities() {
        super();
    }
    
    public static Date parseStrToDate(String strDate) {
        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        
        try {
            date = formater.parse(strDate);
        } catch (ParseException e){}
        
        return date;
    }

    public static String parseDateToStr(Date date) {
        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
        String sDate = null;
        
        sDate = formater.format(date);
        
        return sDate;
    }
    
    public static String formatDate(Date date) {
        SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
        String sDate = null;
        
        sDate = formater.format(date);
        
        return sDate;
    }
    
    public static Date formatInputDate(String strDate) {
        SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
        formater.setLenient(false);
        
        Date date = null;
        
        try {
            date = formater.parse(strDate);
        } catch (ParseException e){ date = null; }
        
        return date;
    }
    
    public static java.sql.Date parseToSQLDate(java.util.Date date) {
        java.sql.Date sqlDate = new java.sql.Date(date.getTime());
        return sqlDate;
    }
	
    public static boolean isReallyEmptyOrNull(String cadena) {
        return cadena == null ? true : cadena.trim().isEmpty();
    }

    /*
    Connection conex = PoolConexion.getInstance().getConexion();

        try {
            PoolConexion.getInstance().beginTransaction(conex);
	    
            PoolConexion.getInstance().commit(conex);
            PoolConexion.getInstance().endTransaction(conex);
        } finally {
            PoolConexion.getInstance().cerrarConexion(conex);
        }
    */

    /*
    stm = conexion.prepareStatement(Sentencia Sql);
            stm.setString(index++, Atributo de clase);
            stm.setFloat(index++, Atributo de clase);
            stm.setString(index++, Atributo de clase);
            stm.executeUpdate() o stm.executeQuery();
    */
}
